package kr.ac.kongju.gedl.admin.web;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;


import kr.ac.kongju.gedl.admin.service.AdminService;
import kr.ac.kongju.gedl.admin.vo.AdminInfoVO;
import kr.ac.kongju.gedl.attach.vo.AttachFileVO;
import kr.ac.kongju.gedl.board.service.BoardContentsService;
import kr.ac.kongju.gedl.board.vo.ContentsVO;
import kr.ac.kongju.gedl.cmmn.web.CU;
import kr.ac.kongju.gedl.code.vo.CodeInfoVO;
import kr.ac.kongju.gedl.common.util.ListResultVO;
import kr.ac.kongju.gedl.item.service.ItemService;
import kr.ac.kongju.gedl.item.vo.ItemInfoVO;
import kr.ac.kongju.gedl.item.vo.ItemVO;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.dozer.DozerBeanMapperSingletonWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.MultipartRequest;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJacksonJsonView;


import egovframework.rte.fdl.property.EgovPropertyService;

@Controller
public class AdminController {
	
	/** EgovPropertyService */
    @Resource(name = "propertiesService")
    protected EgovPropertyService propertiesService;
    
    @Resource(name = "adminService")
    protected AdminService adminService;
    
    @Resource(name = "ajaxResultView")
	protected MappingJacksonJsonView ajaxResultView;
    
    private final Logger logger = LoggerFactory.getLogger(getClass());
    
    
    @RequestMapping(value="/admin/login.do")
	public String login(SessionStatus status) throws Exception {
    	
		return "/admin/login";
	}
    
    
    @RequestMapping(value="/admin/loginChk.do", method=RequestMethod.POST)
	public ModelAndView loginChk(@ModelAttribute("AdminInfo") AdminInfoVO searchVO, HttpSession session,
    		SessionStatus status) throws Exception {
		
    	AdminInfoVO adminInfo = adminService.selectUser(searchVO);
    	Map<String, Object> map = new HashMap<String, Object>();
    	boolean isAdmin = false;
    	if(adminInfo != null && !StringUtils.isEmpty(adminInfo.getAdminId()) && !StringUtils.isEmpty(adminInfo.getPassword())) {
    		isAdmin = true;
    		session.setAttribute("ADMIN_INFO", adminInfo);
    	}
    	
    	map.put("isAdmin", isAdmin);
    	
    	return new ModelAndView(ajaxResultView, map); 
	}
    
    
}
